package com.zhike.b2b.user.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.zhike.b2b.Query;
import com.zhike.b2b.base.BaseService;
import com.zhike.b2b.model.UserCore;
import com.zhike.b2b.user.IUserService;

@Service
public class UserService  extends BaseService implements IUserService {

	public List<UserCore> getAdminByName(String userName) {
		List<UserCore> lu = jt.query(Query.user_info_SEL_BY_USERNAME,
				new Object[] { userName }, new RowMapper<UserCore>() {
					public UserCore mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						UserCore uc = new UserCore();
						uc.setUserName(rs.getString("user_name"));
						uc.setUserState(rs.getString("user_state"));
						uc.setPasswd(rs.getString("passwd"));
						uc.setUserType(rs.getString("user_type"));
						uc.setIp(rs.getString("ip"));
						uc.setCustId(rs.getString("cust_id"));
						uc.setCustName(rs.getString("cust_name"));
						uc.setUserId(rs.getString("user_id"));
						uc.setContactName(rs.getString("contact_name"));
						uc.setRoleAuthId(rs.getString("role_auth_id"));
						return uc;
					}
				});
		return lu;
	}
	
	/**
	 * 根据公司ID查询公司信息，放入用户核心信息中
	 * @param uc
	 */
	public void getUserComInfo(final UserCore uc)
	{
		jt.query(Query.user_info_SEL_CUST_BY_ID,new Object[] { uc.getCustId() }, new RowMapper<UserCore>() {
			public UserCore mapRow(ResultSet rs, int rowNum)
			throws SQLException {
			    uc.setCustType(rs.getString("CUST_TYPE"));
			    uc.setLevelId(rs.getString("LEVEL_ID"));
		    return uc;
	       }
         });
	}

}
